<?php

class RegistrationModel extends Model
{
	function RegisterUser( $username, $password, $email )
	{
		$password = sha1( $password );

		$stmt = $this->db->Prepare( "INSERT INTO Users (Username, Password, Email) VALUES(?, UNHEX(?), ?)" );
		$stmt->bind_param( "sss", $username, $password, $email );
		$stmt->execute();
		$stmt->close();
	}

	function DoesNameExist( $username ) 
	{
		$stmt = $this->db->Prepare("SELECT Username FROM Users WHERE Username = ?");
		$stmt->bind_param( "s", $username );
		$stmt->execute();
		$stmt->bind_result( $row_username );
		$stmt->fetch();
		$exists = ( $username == $row_username );
		$stmt->close();

		return $exists;
	}
	
	function PasswordMatch( $password, $passwordRepeat )
	{	
		return $password = ( $password === $passwordRepeat );
	}
}
